package dper.study.codes.common.simulation4jvmstudy;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by leichen on 2017/5/18.
 */
public class ResourcePool {

    private BlockingQueue<Object> pool = new LinkedBlockingQueue<Object>();

    private static ResourcePool instance = new ResourcePool(2);

    public ResourcePool(int size){
        for(int i = 0; i < size; i++){
            pool.offer(new Object());
        }
    }

    public void hello() throws InterruptedException {
        Object resource = pool.take();
        Thread.sleep(1000);
        pool.offer(resource);
    }

    public static ResourcePool getInstance(){
        return instance;
    }
}
